package com.guigusuqi.commonutils.handler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j//日志功能
public class MyMetaHandler implements MetaObjectHandler
{
    //插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject)
    {
        //设置要往哪个数据库的列表添加数据
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);

        this.setFieldValByName("createBy","苏七",metaObject);
        this.setFieldValByName("updateBy","苏七",metaObject);
        this.setFieldValByName("delFlag","0",metaObject);//添加了逻辑删除注解 就不需要自动填充了
    }
    //更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject)
    {
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("updateBy","苏七",metaObject);
    }
}


